package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/29 11:36
 **/
public class Day44_4_Offer05_ReplaceSpace {
    class Solution1 {
        public String replaceSpace(String s) {
            StringBuilder ans = new StringBuilder();
            for(int i = 0; i < s.length(); ++i){
                if(s.charAt(i) == ' ') ans.append("%20");
                else ans.append(s.charAt(i));
            }
            return ans.toString();
        }
    }
    // 分割字符串会将"   "改错，所以不取用
    class Solution2 {
        public String replaceSpace(String s) {
            String[] arr = s.split(" ");
            String ans = "";
            for(int i = 0; i < arr.length; ++i){
                ans += arr[i];
                if(i != arr.length-1)
                    ans += "%20";
            }
            return ans;
        }
    }
}